<?php
class DefaultController extends Controller{
    public function index(){
        $de_mode = MM('default');
        //$de_mode->index();
        $arr = $de_mode->get(array(
            'conditions'=>'v_id=1'
        ));
        p($arr);
    }

    public function get_js(){
        $callback = $_GET['callback'];
        $data = array('a','b','c');
        echo $callback.'('.json_encode($data).')';
    }

    public function qrcode(){
        $lib = ML('qrcode');
        $arr = $lib->qrcode('http://www.baidu.com');
        p($arr);
    }
    public function iconv(){
        $lib = ML('iconv');
        $data = $de_mode = MM('default')->find();
        $export = $lib->export_to_csv('dqwwqd',$data);
        exit;
    }

    public function ftp_move(){
        $lib = ML('ftp');
        $local_file_name = '5351814464472.jpg';
        $ftp_file_name = 'dwq.jpg';
        $local_url = DOMAIN.'/public/img/'.$local_file_name;
        $ftp_url = 'test/'.$ftp_file_name;
        $arr = array(
            'local_url'=>$local_url,
            'ftp_url'=>$ftp_url
        );
        $bool = $lib->ftp_move_file($arr);
        p($bool);
    }
    public function http_request(){
        $param = array(
            'url'=>'ds.com/api.php?app=api',
            'data'=>'appName=norder&action=getExpressInfo&expresscode=PSH20161224026'
        );
        $res = http_request($param);
        p($res);
    }
    public function upload(){
        if(IS_POST){

            if ($_FILES["Filedata"]["error"] > 0){
                $arrData = array(
                    'status'=>0,
                    'error'=>$_FILES["file"]["error"]
                );
            }else{
                $bool = move_uploaded_file($_FILES['Filedata']['tmp_name'],APP_PUBLIC.'/img/dwqqwwq.jpg');
                $arrData = array(
                    'status'=>1,
                    'thumbnail'=>'http://ecnews.com/public/img/dwqqwwq.jpg',
                    'file_id'=>100
                );
            }
            echo json_encode($arrData);exit;
        }else{

            $swfurl = 'http://ecnews.com/public/plug/swfupload/swfupload.swf';
            $this->smarty->assign('swfurl',$swfurl);
            $this->smarty->display('default/default.html');
        }
    }
    public function mkdir(){
        sy_mkdir(APP_PUBLIC.'/test/xx/yy');
    }

    public function upload_img(){
        if(IS_POST){
            $file = $_FILES['file'];
            $uploader = ML('upload');
            $uploader->allowed_size(20);
            $uploader->allowed_type('dwqw');
            $file_arr = $uploader->upload_file($file,'test/test','hehe');

            p($file_arr);

        }else{
            $this->smarty->display('default/upload_img.html');
        }
    }
}

